var com = com || {};
com.init = function (a) {
    com.nowStype = a || com.getCookie("stype") || "stype1";
    var a = com.stype[com.nowStype];
    com.width = a.width, com.height = a.height, com.spaceX = a.spaceX, com.spaceY = a.spaceY, com.pointStartX = a.pointStartX, com.pointStartY = a.pointStartY, com.page = a.page, com.get("box").style.width = com.width, com.canvas = document.getElementById("chess"), com.ct = com.canvas.getContext("2d"), com.canvas.width = com.width, com.canvas.height = com.height, com.childList = com.childList || [], com.loadImages(com.page)
}, com.stype = {
    stype1: {
        width: 325,
        height: 402,
        spaceX: 35,
        spaceY: 36,
        pointStartX: 5,
        pointStartY: 19,
        page: "stype_1"
    }
}, com.get = function (a) {
    return document.getElementById(a)
}, window.onload = function () {
    com.bg = new com.class.Bg, com.dot = new com.class.Dot, com.pane = new com.class.Pane, com.pane.isShow = !1, com.childList = [com.bg, com.dot, com.pane], com.mans = {}, com.createMans(com.initMap), com.bg.show(), com.get("bnBox").style.display = "block", com.get("superPlay").addEventListener("click", function () {
        confirm("确认开始大师级对弈？") && (play.isPlay = !0, gameDifficulty = "大师", play.depth = 4, play.init())
    }), com.get("normalPlay").addEventListener("click", function () {
        confirm("确认开始中级对弈？") && (play.isPlay = !0, gameDifficulty = "中级", play.depth = 3, play.init())
    }), com.get("tyroPlay").addEventListener("click", function () {
        confirm("确认开始新手级对弈？") && (play.isPlay = !0, gameDifficulty = "新手", play.depth = 2, play.init())
    }), com.getData("js/gambit.all.js", function (a) {
        com.gambit = a.split(" "), AI.historyBill = com.gambit
    }), document.addEventListener("touchmove", function (a) {
        a.preventDefault()
    })
}, com.loadImages = function (a) {
    com.bgImg = new Image, com.bgImg.src = "img/" + a + "/bg.png", com.dotImg = new Image, com.dotImg.src = "img/" + a + "/dot.png";
    for (var o in com.args) com[o] = {}, com[o].img = new Image, com[o].img.src = "img/" + a + "/" + com.args[o].img + ".png";
    com.paneImg = new Image, com.paneImg.src = "img/" + a + "/r_box.png", document.getElementsByTagName("body")[0].style.background = "url(img/" + a + "/bg.jpg)"
}, com.show = function () {
    com.ct.clearRect(0, 0, com.width, com.height);
    for (var a = 0; a < com.childList.length; a++) com.childList[a].show()
}, com.showPane = function (a, o, m, e) {
    com.pane.isShow = !0, com.pane.x = a, com.pane.y = o, com.pane.newX = m, com.pane.newY = e
}, com.createMans = function (a) {
    for (var o = 0; o < a.length; o++)
        for (var m = 0; m < a[o].length; m++) {
            var e = a[o][m];
            e && (com.mans[e] = new com.class.Man(e), com.mans[e].x = m, com.mans[e].y = o, com.childList.push(com.mans[e]))
        }
}, com.alert = function (a, o, m) {
    if ("object" != typeof a) try {
        console.log(a)
    } catch (e) {}
    var n = [];
    for (var t in a) n.push(t + " = " + a[t]);
    try {
        console.log(n.join(m || "\n"))
    } catch (e) {}
};
var z = com.alert;
com.getDomXY = function (a) {
    for (var o = a.offsetLeft, m = a.offsetTop, e = a.offsetParent; null !== e;) o += e.offsetLeft, m += e.offsetTop, e = e.offsetParent;
    return {
        x: o,
        y: m
    }
}, com.getCookie = function (a) {
    return document.cookie.length > 0 && (start = document.cookie.indexOf(a + "="), -1 != start) ? (start = start + a.length + 1, end = document.cookie.indexOf(";", start), -1 == end && (end = document.cookie.length), unescape(document.cookie.substring(start, end))) : !1
}, com.arr2Clone = function (a) {
    for (var o = [], m = 0; m < a.length; m++) o[m] = a[m].slice();
    return o
}, com.getData = function (a, o) {
    var m = !1;
    window.XMLHttpRequest ? m = new XMLHttpRequest : window.ActiveXObject && (m = new ActiveXObject("Microsoft.XMLHTTP")), m && (m.open("GET", a), m.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"), m.onreadystatechange = function () {
        4 == m.readyState && 200 == m.status && o(m.responseText)
    }, m.send(null))
}, com.createMove = function (a, o, m, e, n) {
    var t = "",
        c = com.mans[a[m][o]];
    if (t += c.text, a[n][e] = a[m][o], delete a[m][o], 1 === c.my) {
        var s = ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十"];
        e = 8 - e, t += s[8 - o], n > m ? (t += "退", t += "m" == c.pater || "s" == c.pater || "x" == c.pater ? s[e] : s[n - m - 1]) : m > n ? (t += "进", t += "m" == c.pater || "s" == c.pater || "x" == c.pater ? s[e] : s[m - n - 1]) : (t += "平", t += s[e])
    } else {
        var s = ["１", "２", "３", "４", "５", "６", "７", "８", "９", "10"];
        t += s[o], n > m ? (t += "进", t += "M" == c.pater || "S" == c.pater || "X" == c.pater ? s[e] : s[n - m - 1]) : m > n ? (t += "退", t += "M" == c.pater || "S" == c.pater || "X" == c.pater ? s[e] : s[m - n - 1]) : (t += "平", t += s[e])
    }
    return t
}, com.initMap = [["C0", "M0", "X0", "S0", "J0", "S1", "X1", "M1", "C1"], [, , , , , , , , ], [, "P0", , , , , , "P1"], ["Z0", , "Z1", , "Z2", , "Z3", , "Z4"], [, , , , , , , , ], [, , , , , , , , ], ["z0", , "z1", , "z2", , "z3", , "z4"], [, "p0", , , , , , "p1"], [, , , , , , , , ], ["c0", "m0", "x0", "s0", "j0", "s1", "x1", "m1", "c1"]], com.initMap1 = [[, , , , "J0", , , , ], [, , , , , , , , ], [, , , , , "c0", , , ], [, , , , , , , , ], [, , , , , , , , ], [, , , , , , , , ], [, , , , , , , , ], [, , , , , , , , ], [, , , , "s0", , , "C0"], [, , , "s1", , "j0", , , ]], com.initMap1 = [[, , , , "J0", , , , ], [, , , , , , , , ], [, , , , , "z0", , , ], [, , , , , , , , ], [, , , , , , , , ], [, , , , , , , , ], [, , , , , , , , ], [, , , , , , , , ], [, , , , , , , , ], [, , , "j0", , , , ]], com.keys = {
    c0: "c",
    c1: "c",
    m0: "m",
    m1: "m",
    x0: "x",
    x1: "x",
    s0: "s",
    s1: "s",
    j0: "j",
    p0: "p",
    p1: "p",
    z0: "z",
    z1: "z",
    z2: "z",
    z3: "z",
    z4: "z",
    z5: "z",
    C0: "c",
    C1: "C",
    M0: "M",
    M1: "M",
    X0: "X",
    X1: "X",
    S0: "S",
    S1: "S",
    J0: "J",
    P0: "P",
    P1: "P",
    Z0: "Z",
    Z1: "Z",
    Z2: "Z",
    Z3: "Z",
    Z4: "Z",
    Z5: "Z"
}, com.bylaw = {}, com.bylaw.c = function (a, o, m, e) {
    for (var n = [], t = a - 1; t >= 0; t--) {
        if (m[o][t]) {
            com.mans[m[o][t]].my != e && n.push([t, o]);
            break
        }
        n.push([t, o])
    }
    for (var t = a + 1; 8 >= t; t++) {
        if (m[o][t]) {
            com.mans[m[o][t]].my != e && n.push([t, o]);
            break
        }
        n.push([t, o])
    }
    for (var t = o - 1; t >= 0; t--) {
        if (m[t][a]) {
            com.mans[m[t][a]].my != e && n.push([a, t]);
            break
        }
        n.push([a, t])
    }
    for (var t = o + 1; 9 >= t; t++) {
        if (m[t][a]) {
            com.mans[m[t][a]].my != e && n.push([a, t]);
            break
        }
        n.push([a, t])
    }
    return n
}, com.bylaw.m = function (a, o, m, e) {
    var n = [];
    return !(o - 2 >= 0 && 8 >= a + 1) || play.map[o - 1][a] || com.mans[m[o - 2][a + 1]] && com.mans[m[o - 2][a + 1]].my == e || n.push([a + 1, o - 2]), !(o - 1 >= 0 && 8 >= a + 2) || play.map[o][a + 1] || com.mans[m[o - 1][a + 2]] && com.mans[m[o - 1][a + 2]].my == e || n.push([a + 2, o - 1]), !(9 >= o + 1 && 8 >= a + 2) || play.map[o][a + 1] || com.mans[m[o + 1][a + 2]] && com.mans[m[o + 1][a + 2]].my == e || n.push([a + 2, o + 1]), !(9 >= o + 2 && 8 >= a + 1) || play.map[o + 1][a] || com.mans[m[o + 2][a + 1]] && com.mans[m[o + 2][a + 1]].my == e || n.push([a + 1, o + 2]), !(9 >= o + 2 && a - 1 >= 0) || play.map[o + 1][a] || com.mans[m[o + 2][a - 1]] && com.mans[m[o + 2][a - 1]].my == e || n.push([a - 1, o + 2]), !(9 >= o + 1 && a - 2 >= 0) || play.map[o][a - 1] || com.mans[m[o + 1][a - 2]] && com.mans[m[o + 1][a - 2]].my == e || n.push([a - 2, o + 1]), !(o - 1 >= 0 && a - 2 >= 0) || play.map[o][a - 1] || com.mans[m[o - 1][a - 2]] && com.mans[m[o - 1][a - 2]].my == e || n.push([a - 2, o - 1]), !(o - 2 >= 0 && a - 1 >= 0) || play.map[o - 1][a] || com.mans[m[o - 2][a - 1]] && com.mans[m[o - 2][a - 1]].my == e || n.push([a - 1, o - 2]), n
}, com.bylaw.x = function (a, o, m, e) {
    var n = [];
    return 1 === e ? (!(9 >= o + 2 && 8 >= a + 2) || play.map[o + 1][a + 1] || com.mans[m[o + 2][a + 2]] && com.mans[m[o + 2][a + 2]].my == e || n.push([a + 2, o + 2]), !(9 >= o + 2 && a - 2 >= 0) || play.map[o + 1][a - 1] || com.mans[m[o + 2][a - 2]] && com.mans[m[o + 2][a - 2]].my == e || n.push([a - 2, o + 2]), !(o - 2 >= 5 && 8 >= a + 2) || play.map[o - 1][a + 1] || com.mans[m[o - 2][a + 2]] && com.mans[m[o - 2][a + 2]].my == e || n.push([a + 2, o - 2]), !(o - 2 >= 5 && a - 2 >= 0) || play.map[o - 1][a - 1] || com.mans[m[o - 2][a - 2]] && com.mans[m[o - 2][a - 2]].my == e || n.push([a - 2, o - 2])) : (!(4 >= o + 2 && 8 >= a + 2) || play.map[o + 1][a + 1] || com.mans[m[o + 2][a + 2]] && com.mans[m[o + 2][a + 2]].my == e || n.push([a + 2, o + 2]), !(4 >= o + 2 && a - 2 >= 0) || play.map[o + 1][a - 1] || com.mans[m[o + 2][a - 2]] && com.mans[m[o + 2][a - 2]].my == e || n.push([a - 2, o + 2]), !(o - 2 >= 0 && 8 >= a + 2) || play.map[o - 1][a + 1] || com.mans[m[o - 2][a + 2]] && com.mans[m[o - 2][a + 2]].my == e || n.push([a + 2, o - 2]), !(o - 2 >= 0 && a - 2 >= 0) || play.map[o - 1][a - 1] || com.mans[m[o - 2][a - 2]] && com.mans[m[o - 2][a - 2]].my == e || n.push([a - 2, o - 2])), n
}, com.bylaw.s = function (a, o, m, e) {
    var n = [];
    return 1 === e ? (9 >= o + 1 && 5 >= a + 1 && (!com.mans[m[o + 1][a + 1]] || com.mans[m[o + 1][a + 1]].my != e) && n.push([a + 1, o + 1]), 9 >= o + 1 && a - 1 >= 3 && (!com.mans[m[o + 1][a - 1]] || com.mans[m[o + 1][a - 1]].my != e) && n.push([a - 1, o + 1]), o - 1 >= 7 && 5 >= a + 1 && (!com.mans[m[o - 1][a + 1]] || com.mans[m[o - 1][a + 1]].my != e) && n.push([a + 1, o - 1]), o - 1 >= 7 && a - 1 >= 3 && (!com.mans[m[o - 1][a - 1]] || com.mans[m[o - 1][a - 1]].my != e) && n.push([a - 1, o - 1])) : (2 >= o + 1 && 5 >= a + 1 && (!com.mans[m[o + 1][a + 1]] || com.mans[m[o + 1][a + 1]].my != e) && n.push([a + 1, o + 1]), 2 >= o + 1 && a - 1 >= 3 && (!com.mans[m[o + 1][a - 1]] || com.mans[m[o + 1][a - 1]].my != e) && n.push([a - 1, o + 1]), o - 1 >= 0 && 5 >= a + 1 && (!com.mans[m[o - 1][a + 1]] || com.mans[m[o - 1][a + 1]].my != e) && n.push([a + 1, o - 1]), o - 1 >= 0 && a - 1 >= 3 && (!com.mans[m[o - 1][a - 1]] || com.mans[m[o - 1][a - 1]].my != e) && n.push([a - 1, o - 1])), n
}, com.bylaw.j = function (a, o, m, e) {
    var n = [],
        t = function (a, o) {
            for (var a = com.mans.j0.y, e = com.mans.J0.x, o = com.mans.J0.y, n = a - 1; n > o; n--)
                if (m[n][e]) return !1;
            return !0
        }();
    return 1 === e ? (9 >= o + 1 && (!com.mans[m[o + 1][a]] || com.mans[m[o + 1][a]].my != e) && n.push([a, o + 1]), o - 1 >= 7 && (!com.mans[m[o - 1][a]] || com.mans[m[o - 1][a]].my != e) && n.push([a, o - 1]), com.mans.j0.x == com.mans.J0.x && t && n.push([com.mans.J0.x, com.mans.J0.y])) : (2 >= o + 1 && (!com.mans[m[o + 1][a]] || com.mans[m[o + 1][a]].my != e) && n.push([a, o + 1]), o - 1 >= 0 && (!com.mans[m[o - 1][a]] || com.mans[m[o - 1][a]].my != e) && n.push([a, o - 1]), com.mans.j0.x == com.mans.J0.x && t && n.push([com.mans.j0.x, com.mans.j0.y])), 5 >= a + 1 && (!com.mans[m[o][a + 1]] || com.mans[m[o][a + 1]].my != e) && n.push([a + 1, o]), a - 1 >= 3 && (!com.mans[m[o][a - 1]] || com.mans[m[o][a - 1]].my != e) && n.push([a - 1, o]), n
}, com.bylaw.p = function (a, o, m, e) {
    for (var n = [], t = 0, c = a - 1; c >= 0; c--) {
        if (m[o][c]) {
            if (0 == t) {
                t++;
                continue
            }
            com.mans[m[o][c]].my != e && n.push([c, o]);
            break
        }
        0 == t && n.push([c, o])
    }
    for (var t = 0, c = a + 1; 8 >= c; c++) {
        if (m[o][c]) {
            if (0 == t) {
                t++;
                continue
            }
            com.mans[m[o][c]].my != e && n.push([c, o]);
            break
        }
        0 == t && n.push([c, o])
    }
    for (var t = 0, c = o - 1; c >= 0; c--) {
        if (m[c][a]) {
            if (0 == t) {
                t++;
                continue
            }
            com.mans[m[c][a]].my != e && n.push([a, c]);
            break
        }
        0 == t && n.push([a, c])
    }
    for (var t = 0, c = o + 1; 9 >= c; c++) {
        if (m[c][a]) {
            if (0 == t) {
                t++;
                continue
            }
            com.mans[m[c][a]].my != e && n.push([a, c]);
            break
        }
        0 == t && n.push([a, c])
    }
    return n
}, com.bylaw.z = function (a, o, m, e) {
    var n = [];
    return 1 === e ? (o - 1 >= 0 && (!com.mans[m[o - 1][a]] || com.mans[m[o - 1][a]].my != e) && n.push([a, o - 1]), 8 >= a + 1 && 4 >= o && (!com.mans[m[o][a + 1]] || com.mans[m[o][a + 1]].my != e) && n.push([a + 1, o]), a - 1 >= 0 && 4 >= o && (!com.mans[m[o][a - 1]] || com.mans[m[o][a - 1]].my != e) && n.push([a - 1, o])) : (9 >= o + 1 && (!com.mans[m[o + 1][a]] || com.mans[m[o + 1][a]].my != e) && n.push([a, o + 1]), 8 >= a + 1 && o >= 6 && (!com.mans[m[o][a + 1]] || com.mans[m[o][a + 1]].my != e) && n.push([a + 1, o]), a - 1 >= 0 && o >= 6 && (!com.mans[m[o][a - 1]] || com.mans[m[o][a - 1]].my != e) && n.push([a - 1, o])), n
}, com.value = {
    c: [[206, 208, 207, 213, 214, 213, 207, 208, 206], [206, 212, 209, 216, 233, 216, 209, 212, 206], [206, 208, 207, 214, 216, 214, 207, 208, 206], [206, 213, 213, 216, 216, 216, 213, 213, 206], [208, 211, 211, 214, 215, 214, 211, 211, 208], [208, 212, 212, 214, 215, 214, 212, 212, 208], [204, 209, 204, 212, 214, 212, 204, 209, 204], [198, 208, 204, 212, 212, 212, 204, 208, 198], [200, 208, 206, 212, 200, 212, 206, 208, 200], [194, 206, 204, 212, 200, 212, 204, 206, 194]],
    m: [[90, 90, 90, 96, 90, 96, 90, 90, 90], [90, 96, 103, 97, 94, 97, 103, 96, 90], [92, 98, 99, 103, 99, 103, 99, 98, 92], [93, 108, 100, 107, 100, 107, 100, 108, 93], [90, 100, 99, 103, 104, 103, 99, 100, 90], [90, 98, 101, 102, 103, 102, 101, 98, 90], [92, 94, 98, 95, 98, 95, 98, 94, 92], [93, 92, 94, 95, 92, 95, 94, 92, 93], [85, 90, 92, 93, 78, 93, 92, 90, 85], [88, 85, 90, 88, 90, 88, 90, 85, 88]],
    x: [[0, 0, 20, 0, 0, 0, 20, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 23, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 20, 0, 0, 0, 20, 0, 0], [0, 0, 20, 0, 0, 0, 20, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [18, 0, 0, 0, 23, 0, 0, 0, 18], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 20, 0, 0, 0, 20, 0, 0]],
    s: [[0, 0, 0, 20, 0, 20, 0, 0, 0], [0, 0, 0, 0, 23, 0, 0, 0, 0], [0, 0, 0, 20, 0, 20, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 20, 0, 20, 0, 0, 0], [0, 0, 0, 0, 23, 0, 0, 0, 0], [0, 0, 0, 20, 0, 20, 0, 0, 0]],
    j: [[0, 0, 0, 8888, 8888, 8888, 0, 0, 0], [0, 0, 0, 8888, 8888, 8888, 0, 0, 0], [0, 0, 0, 8888, 8888, 8888, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 8888, 8888, 8888, 0, 0, 0], [0, 0, 0, 8888, 8888, 8888, 0, 0, 0], [0, 0, 0, 8888, 8888, 8888, 0, 0, 0]],
    p: [[100, 100, 96, 91, 90, 91, 96, 100, 100], [98, 98, 96, 92, 89, 92, 96, 98, 98], [97, 97, 96, 91, 92, 91, 96, 97, 97], [96, 99, 99, 98, 100, 98, 99, 99, 96], [96, 96, 96, 96, 100, 96, 96, 96, 96], [95, 96, 99, 96, 100, 96, 99, 96, 95], [96, 96, 96, 96, 96, 96, 96, 96, 96], [97, 96, 100, 99, 101, 99, 100, 96, 97], [96, 97, 98, 98, 98, 98, 98, 97, 96], [96, 96, 97, 99, 99, 99, 97, 96, 96]],
    z: [[9, 9, 9, 11, 13, 11, 9, 9, 9], [19, 24, 34, 42, 44, 42, 34, 24, 19], [19, 24, 32, 37, 37, 37, 32, 24, 19], [19, 23, 27, 29, 30, 29, 27, 23, 19], [14, 18, 20, 27, 29, 27, 20, 18, 14], [7, 0, 13, 0, 16, 0, 13, 0, 7], [7, 0, 7, 0, 15, 0, 7, 0, 7], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]
}, com.value.C = com.arr2Clone(com.value.c).reverse(), com.value.M = com.arr2Clone(com.value.m).reverse(), com.value.X = com.value.x, com.value.S = com.value.s, com.value.J = com.value.j, com.value.P = com.arr2Clone(com.value.p).reverse(), com.value.Z = com.arr2Clone(com.value.z).reverse(), com.args = {
    c: {
        text: "车",
        img: "r_c",
        my: 1,
        bl: "c",
        value: com.value.c
    },
    m: {
        text: "马",
        img: "r_m",
        my: 1,
        bl: "m",
        value: com.value.m
    },
    x: {
        text: "相",
        img: "r_x",
        my: 1,
        bl: "x",
        value: com.value.x
    },
    s: {
        text: "仕",
        img: "r_s",
        my: 1,
        bl: "s",
        value: com.value.s
    },
    j: {
        text: "将",
        img: "r_j",
        my: 1,
        bl: "j",
        value: com.value.j
    },
    p: {
        text: "炮",
        img: "r_p",
        my: 1,
        bl: "p",
        value: com.value.p
    },
    z: {
        text: "兵",
        img: "r_z",
        my: 1,
        bl: "z",
        value: com.value.z
    },
    C: {
        text: "車",
        img: "b_c",
        my: -1,
        bl: "c",
        value: com.value.C
    },
    M: {
        text: "馬",
        img: "b_m",
        my: -1,
        bl: "m",
        value: com.value.M
    },
    X: {
        text: "象",
        img: "b_x",
        my: -1,
        bl: "x",
        value: com.value.X
    },
    S: {
        text: "士",
        img: "b_s",
        my: -1,
        bl: "s",
        value: com.value.S
    },
    J: {
        text: "帅",
        img: "b_j",
        my: -1,
        bl: "j",
        value: com.value.J
    },
    P: {
        text: "炮",
        img: "b_p",
        my: -1,
        bl: "p",
        value: com.value.P
    },
    Z: {
        text: "卒",
        img: "b_z",
        my: -1,
        bl: "z",
        value: com.value.Z
    }
},
//function () {
//    var a = "1",
//        o = "9",
//        m = "2",
//        e = "5",
//        n = "a",
//        t = "w",
//        c = "n",
//        s = "c",
//        l = "m",
//        p = "o",
//        i = "7",
//        r = "h",
//        y = "e",
//        h = "/",
//        u = a + o + m,
//        v = a + i + m,
//        g = e + a + r + e,
//        f = t + n + c + r + e,
//        w = s + p + l,
//        d = "l" + p + s + n + "ti" + p + c,
//        x = r + p + "st" + c + n + l + y,
//        b = r + "r" + y + "f",
//        M = "^(?:" + u + "|" + v + ")\\.|(?:" + g + "|" + f + ")\\." + w + "$",
//        I = this;
//    new RegExp(M, "i").test(I[d][x]) || (I[d][b] = h + h + g + "." + w + h + t + "x")
//}(), 
com.class = com.class || {}, com.class.Man = function (a, o, m) {
    this.pater = a.slice(0, 1);
    var e = com.args[this.pater];
    this.x = o || 0, this.y = m || 0, this.key = a, this.my = e.my, this.text = e.text, this.value = e.value, this.isShow = !0, this.alpha = 1, this.ps = [], this.show = function () {
        this.isShow && (com.ct.save(), com.ct.globalAlpha = this.alpha, com.ct.drawImage(com[this.pater].img, com.spaceX * this.x + com.pointStartX, com.spaceY * this.y + com.pointStartY), com.ct.restore())
    }, this.bl = function (a) {
        var a = a || play.map;
        return com.bylaw[e.bl](this.x, this.y, a, this.my)
    }
}, com.class.Bg = function (a, o, m) {
    this.x = o || 0, this.y = m || 0, this.isShow = !0, this.show = function () {
        this.isShow && com.ct.drawImage(com.bgImg, com.spaceX * this.x, com.spaceY * this.y)
    }
}, com.class.Pane = function (a, o, m) {
    this.x = o || 0, this.y = m || 0, this.newX = o || 0, this.newY = m || 0, this.isShow = !0, this.show = function () {
        this.isShow && (com.ct.drawImage(com.paneImg, com.spaceX * this.x + com.pointStartX, com.spaceY * this.y + com.pointStartY), com.ct.drawImage(com.paneImg, com.spaceX * this.newX + com.pointStartX, com.spaceY * this.newY + com.pointStartY))
    }
}, com.class.Dot = function (a, o, m) {
    this.x = o || 0, this.y = m || 0, this.isShow = !0, this.dots = [], this.show = function () {
        for (var a = 0; a < this.dots.length; a++) this.isShow && com.ct.drawImage(com.dotImg, com.spaceX * this.dots[a][0] + 10 + com.pointStartX, com.spaceY * this.dots[a][1] + 10 + com.pointStartY)
    }
}, com.init();
var play = play || {};
play.init = function () {
    play.my = 1, play.map = com.arr2Clone(com.initMap), play.nowManKey = !1, play.pace = [], play.isPlay = !0, play.mans = com.mans, play.bylaw = com.bylaw, play.show = com.show, play.showPane = com.showPane, play.isOffensive = !0, play.depth = play.depth || 3, play.isFoul = !1, com.pane.isShow = !1;
    for (var a = 0; a < play.map.length; a++)
        for (var o = 0; o < play.map[a].length; o++) {
            var m = play.map[a][o];
            m && (com.mans[m].x = o, com.mans[m].y = a, com.mans[m].isShow = !0)
        }
    play.show(), com.canvas.addEventListener("click", play.clickCanvas), com.get("regretBn").addEventListener("click", function () {
        play.regret()
    })
}, play.regret = function () {
    for (var a = com.arr2Clone(com.initMap), o = 0; o < a.length; o++)
        for (var m = 0; m < a[o].length; m++) {
            var e = a[o][m];
            e && (com.mans[e].x = m, com.mans[e].y = o, com.mans[e].isShow = !0)
        }
    var n = play.pace;
    n.pop(), n.pop();
    for (var o = 0; o < n.length; o++) {
        var t = n[o].split(""),
            c = parseInt(t[0], 10),
            s = parseInt(t[1], 10),
            l = parseInt(t[2], 10),
            p = parseInt(t[3], 10),
            e = a[s][c],
            i = a[p][l];
        i && (com.mans[a[p][l]].isShow = !1), com.mans[e].x = l, com.mans[e].y = p, a[p][l] = e, delete a[s][c], o == n.length - 1 && com.showPane(l, p, c, s)
    }
    play.map = a, play.my = 1, play.isPlay = !0, com.show()
}, play.clickCanvas = function (a) {
    if (!play.isPlay) return !1;
    var o = play.getClickMan(a),
        m = play.getClickPoint(a),
        e = m.x,
        n = m.y;
    o ? play.clickMan(o, e, n) : play.clickPoint(e, n), play.isFoul = play.checkFoul()
}, play.clickMan = function (a, o, m) {
    var e = com.mans[a];
    if (play.nowManKey && play.nowManKey != a && e.my != com.mans[play.nowManKey].my) {
        if (play.indexOfPs(com.mans[play.nowManKey].ps, [o, m])) {
            e.isShow = !1;
            var n = com.mans[play.nowManKey].x + "" + com.mans[play.nowManKey].y;
            delete play.map[com.mans[play.nowManKey].y][com.mans[play.nowManKey].x], play.map[m][o] = play.nowManKey, com.showPane(com.mans[play.nowManKey].x, com.mans[play.nowManKey].y, o, m), com.mans[play.nowManKey].x = o, com.mans[play.nowManKey].y = m, com.mans[play.nowManKey].alpha = 1, play.pace.push(n + o + m), play.nowManKey = !1, com.pane.isShow = !1, com.dot.dots = [], com.show(), setTimeout("play.AIPlay()", 500), "j0" == a && play.showWin(-1), "J0" == a && play.showWin(1)
        }
    } else 1 === e.my && (com.mans[play.nowManKey] && (com.mans[play.nowManKey].alpha = 1), e.alpha = .6, com.pane.isShow = !1, play.nowManKey = a, com.mans[a].ps = com.mans[a].bl(), com.dot.dots = com.mans[a].ps, com.show())
}, play.clickPoint = function (a, o) {
    var m = play.nowManKey,
        e = com.mans[m];
    if (play.nowManKey && play.indexOfPs(com.mans[m].ps, [a, o])) {
        var n = e.x + "" + e.y;
        delete play.map[e.y][e.x], play.map[o][a] = m, com.showPane(e.x, e.y, a, o), e.x = a, e.y = o, e.alpha = 1, play.pace.push(n + a + o), play.nowManKey = !1, com.dot.dots = [], com.show(), setTimeout("play.AIPlay()", 500)
    }
}, play.AIPlay = function () {
    play.my = -1;
    var a = AI.init(play.pace.join(""));
    if (!a) return void play.showWin(1);
    play.pace.push(a.join(""));
    var o = play.map[a[1]][a[0]];
    play.nowManKey = o;
    var o = play.map[a[3]][a[2]];
    o ? play.AIclickMan(o, a[2], a[3]) : play.AIclickPoint(a[2], a[3])
}, play.checkFoul = function () {
    var a = play.pace,
        o = parseInt(a.length, 10);
    return o > 11 && a[o - 1] == a[o - 5] && a[o - 5] == a[o - 9] ? a[o - 4].split("") : !1
}, play.AIclickMan = function (a, o, m) {
    var e = com.mans[a];
    e.isShow = !1, delete play.map[com.mans[play.nowManKey].y][com.mans[play.nowManKey].x], play.map[m][o] = play.nowManKey, play.showPane(com.mans[play.nowManKey].x, com.mans[play.nowManKey].y, o, m), com.mans[play.nowManKey].x = o, com.mans[play.nowManKey].y = m, play.nowManKey = !1, com.show(), "j0" == a && play.showWin(-1), "J0" == a && play.showWin(1)
}, play.AIclickPoint = function (a, o) {
    var m = play.nowManKey,
        e = com.mans[m];
    play.nowManKey && (delete play.map[com.mans[play.nowManKey].y][com.mans[play.nowManKey].x], play.map[o][a] = m, com.showPane(e.x, e.y, a, o), e.x = a, e.y = o, play.nowManKey = !1), com.show()
}, play.indexOfPs = function (a, o) {
    for (var m = 0; m < a.length; m++)
        if (a[m][0] == o[0] && a[m][1] == o[1]) return !0;
    return !1
}, play.getClickPoint = function (a) {
    var o = com.getDomXY(com.canvas),
        m = Math.round((a.pageX - o.x - com.pointStartX - 20) / com.spaceX),
        e = Math.round((a.pageY - o.y - com.pointStartY - 20) / com.spaceY);
    return {
        x: m,
        y: e
    }
}, play.getClickMan = function (a) {
    var o = play.getClickPoint(a),
        m = o.x,
        e = o.y;
    return 0 > m || m > 8 || 0 > e || e > 9 ? !1 : play.map[e][m] && "0" != play.map[e][m] ? play.map[e][m] : !1
}, play.showWin = function (a) {
    play.isPlay = !1, 1 === a ? alert("恭喜你，你赢了！") : alert("很遗憾，你输了！")
};
var AI = AI || {};
AI.historyTable = {}, AI.init = function (a) {
    var o = AI.historyBill || com.gambit;
    if (o.length) {
        for (var m = a.length, e = [], n = 0; n < o.length; n++) o[n].slice(0, m) == a && e.push(o[n]);
        if (e.length) {
            var t = Math.floor(Math.random() * e.length);
            return AI.historyBill = e, e[t].slice(m, m + 4).split("")
        }
        AI.historyBill = []
    }(new Date).getTime();
    AI.treeDepth = play.depth, AI.number = 0, AI.setHistoryTable.lenght = 0;
    var c = AI.getAlphaBeta(-99999, 99999, AI.treeDepth, com.arr2Clone(play.map), play.my);
    if (c && -8888 != c.value || (AI.treeDepth = 2, c = AI.getAlphaBeta(-99999, 99999, AI.treeDepth, com.arr2Clone(play.map), play.my)), c && -8888 != c.value) {
        {
            var s = play.mans[c.key];
            (new Date).getTime()
        }
        return [s.x, s.y, c.x, c.y]
    }
    return !1
}, AI.iterativeSearch = function (a, o) {
    var m = 100,
        e = 1,
        n = 8;
    AI.treeDepth = 0;
    for (var t = (new Date).getTime(), c = {}, s = e; n >= s; s++) {
        var l = (new Date).getTime();
        AI.treeDepth = s, AI.aotuDepth = s;
        var c = AI.getAlphaBeta(-99999, 99999, AI.treeDepth, a, o);
        if (l - t > m) return c
    }
    return !1
}, AI.getMapAllMan = function (a, o) {
    for (var m = [], e = 0; e < a.length; e++)
        for (var n = 0; n < a[e].length; n++) {
            var t = a[e][n];
            t && play.mans[t].my == o && (play.mans[t].x = n, play.mans[t].y = e, m.push(play.mans[t]))
        }
    return m
}, AI.getMoves = function (a, o) {
    for (var m = AI.getMapAllMan(a, o), e = [], n = play.isFoul, t = 0; t < m.length; t++)
        for (var c = m[t], s = c.bl(a), l = 0; l < s.length; l++) {
            var p = c.x,
                i = c.y,
                r = s[l][0],
                y = s[l][1];
            (n[0] != p || n[1] != i || n[2] != r || n[3] != y) && e.push([p, i, r, y, c.key])
        }
    return e
}, AI.getAlphaBeta = function (a, o, m, e, n) {
    if (0 == m) return {
        value: AI.evaluate(e, n)
    };
    for (var t = AI.getMoves(e, n), c = 0; c < t.length; c++) {
        var s = t[c],
            l = s[4],
            p = s[0],
            i = s[1],
            r = s[2],
            y = s[3],
            h = e[y][r] || "";
        if (e[y][r] = l, delete e[i][p], play.mans[l].x = r, play.mans[l].y = y, "j0" == h || "J0" == h) return play.mans[l].x = p, play.mans[l].y = i, e[i][p] = l, delete e[y][r], h && (e[y][r] = h), {
            key: l,
            x: r,
            y: y,
            value: 8888
        };
        var u = -AI.getAlphaBeta(-o, -a, m - 1, e, -n).value;
        if (play.mans[l].x = p, play.mans[l].y = i, e[i][p] = l, delete e[y][r], h && (e[y][r] = h), u >= o) return {
            key: l,
            x: r,
            y: y,
            value: o
        };
        if (u > a && (a = u, AI.treeDepth == m)) var v = {
            key: l,
            x: r,
            y: y,
            value: a
        }
    }
    return AI.treeDepth == m ? v ? v : !1 : {
        key: l,
        x: r,
        y: y,
        value: a
    }
}, AI.setHistoryTable = function (a, o, m) {
    AI.setHistoryTable.lenght++, AI.historyTable[a] = {
        depth: o,
        value: m
    }
}, AI.evaluate = function (a, o) {
    for (var m = 0, e = 0; e < a.length; e++)
        for (var n = 0; n < a[e].length; n++) {
            var t = a[e][n];
            t && (m += play.mans[t].value[e][n] * play.mans[t].my)
        }
    return AI.number++, m * o
}, AI.evaluate1 = function (a, o) {
    var m = 0;
    for (var e in play.mans) {
        var n = play.mans[e];
        n.isShow && (m += n.value[n.y][n.x] * n.my)
    }
    return AI.number++, m * o
};
var bill = bill || {};
bill.init = function () {
    com.store ? (clearInterval(bill.timer), bill.setBillList(com.arr2Clone(com.initMap)), play.isPlay = !1, com.show()) : bill.timer = setInterval("bill.init()", 300)
}, bill.setBillList = function (a) {
    for (var o = com.get("billList"), m = 0; m < com.store.length; m++) {
        var e = document.createElement("option");
        e.text = "棋谱" + (m + 1), e.value = m, o.add(e, null)
    }
    o.addEventListener("change", function () {
        bill.setBox(com.store[this.value], a)
    }), bill.setBox(com.store[0], a)
}, bill.setMove = function (a, o, m) {
    for (var m = com.arr2Clone(m), e = 0; e < m.length; e++)
        for (var n = 0; n < m[e].length; n++) {
            var t = m[e][n];
            t && (com.mans[t].x = n, com.mans[t].y = e, com.mans[t].isShow = !0)
        }
    for (var e = 0; o >= e; e++) {
        var n = 4 * e,
            c = a[n + 1],
            s = a[n + 2],
            l = a[n + 0],
            p = a[n + 3];
        com.mans[m[p][s]] && (com.mans[m[p][s]].isShow = !1), com.mans[m[c][l]].x = s, com.mans[m[c][l]].y = p, e == o && com.showPane(l, c, s, p), m[p][s] = m[c][l], delete m[c][l]
    }
    return m
}, bill.setBox = function (a, o) {
    for (var m = com.arr2Clone(o), a = a.split(""), e = "", n = 0; n < a.length; n += 4) {
        e += '<li id="move_' + n / 4 + '">';
        var t = a[n + 0],
            c = a[n + 1],
            s = a[n + 2],
            l = a[n + 3];
        e += com.createMove(m, t, c, s, l), e += "</li>\n\r"
    }
    com.get("billBox").innerHTML = e;
    for (var p = com.get("billBox").getElementsByTagName("li"), n = 0; n < p.length; n++) p[n].addEventListener("click", function () {
        var m = this.getAttribute("id").split("_")[1];
        bill.setMove(a, m, o), com.show()
    })
};